package Gamewudao;

import java.util.Random;

public class Game {
    private Player player;//玩家

    //构造方法传入玩家信息
    public Game(Player player){
        super();
        this.player=player;
    }


    //输出指定级别规定长度的字符串
    public String printStr(){//随机显示提示字符
        int strLength = LevelParam.levels[player.getLevelNo() - 1].getStrLength();
        String buffer ="";
        Random random=new Random();
        int StrLength=player.getLevelNo();
        for (int i=0;i<StrLength;i++){
            int rand=random.nextInt(StrLength);
            switch (rand){
                case 0:
                    buffer+=(">");
                    break;
                case 1:
                    buffer+="<";
                    break;
                case 2:
                    buffer+=("/");
                    break;
                case 3:
                    buffer+=("*");
                    break;
                case 4:
                    buffer+=("=");
                    break;
                case 5:
                    buffer+=("+");
                    break;



            }
        }
        System.out.println(buffer);
        
        return buffer;
    }
    public void printResult (String outstr,String instr){//展示结果
        boolean flag;
        if (outstr.equals(instr)){
            flag=true;//表示玩家获胜
        }else {
            flag=false;//玩家答错
        }
        if (flag){
            long currentTime=System.currentTimeMillis();
            if ((currentTime-player.getStartTime())/1000>LevelParam.levels[player.getLevelNo()].getTimeLimit()){
                System.out.println("你输入的太慢了，已经超时，退出！");
                System.exit(1);
            }else {
                player.setCurrScore(player.getCurrScore()+LevelParam.levels[player.getLevelNo()-1].getPerScore());
                player.setElapsedTime((int) (currentTime-player.getStartTime())/1000);
                System.out.println("输入正确，你的级别："+player.getLevelNo()+",你的积分:"+player.getCurrScore()+"，已用时间:"+player.getElapsedTime()+"秒");
                if (player.getLevelNo()==6){
                    int score=LevelParam.levels[player.getLevelNo()-1].getPerScore()*LevelParam.levels[player.getLevelNo()-1].getStrTimes();
                    if (player.getCurrScore()==score){
                        System.out.println("通关");
                        System.exit(0);
                    }
                }
            }
        }else{
            System.out.println("输入错误！");
            System.exit(1);
        }

    }

}
